package com.xxx.td;

import java.io.IOException;

/**
 * @version v1.0
 * @Description:
 * @Author zhanzhongxin
 * @Date 2021/8/2 10:55
 * @Copyright 博为峰
 */
public class DaemonDemo extends Thread {

    public void run() {
        for (int i = 0; i < 100; i++) {
            try {
                Thread.sleep(50000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "," + i);
        }
    }

    public static void main(String[] args) throws IOException {
        /*
           1.用户线程
           2.守护线程（后台线程），如果JVM中都是守护线程时，JVM退出
         */
        final DaemonDemo daemonDemo = new DaemonDemo();
        daemonDemo.setDaemon(true);//守护线程
        daemonDemo.start();

        System.in.read();

        //main Thread-0(守护线程)
    }
}
